home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12785 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  68 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.inap.net!news1!ind-006-236-238
  3. From: dlmiller@iquest.net (Doug Miller)
  4. Subject: Re: Why does my program do this?
  5. X-Nntp-Posting-Host: ind-006-236-238.iquest.net
  6. Message-ID: <Dp8Lpn.7EB@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <4jnln2$95j@dfw-ixnews3.ix.netcom.com>
  11. Date: Tue, 2 Apr 1996 13:36:59 GMT
  12.  
  13. ishky@ix.netcom.com(Andrew Heiz ) wrote:
  14. >Hi again,
  15. >
  16. >There have been so many helpful readers out there here is another
  17. >question for you.
  18. >
  19. >I've declared an 2 dimentional array:
  20. >
  21. >char scores[STUDENT][5];
  22. >
  23. >I am entering the scores in 2 for loops like this:
  24. >
  25. >    for (i=0; i <= students-1; i=i+1)
  26. >        {
  27. >            for (j=0; j <= tests-1; j=j+1)
  28. >            {
  29. >                gets(&scores[i][j];
  30. >            }
  31. >        }
  32. >
  33. >I print out the scores in the same type of loop structure:
  34. >
  35. >    for (i=0; i <= students-1; i=i+1)
  36. >        {
  37. >        printf("Scores for student %d",i+1);
  38. >            for (j=0; j <= tests-1; j=j+1)
  39. >            {
  40. >                printf("\tGrade %d: %s",j+1,scores[i][j]);
  41. >            }
  42. >        }
  43. >
  44. >I am getting (if you don't already know this):
  45. >
  46. >        Scores for student 1: Grade 1: 999991   Grade 2: 99991   Grade
  47. >3: 9991    Grade 4: 991    Grade 5: 91
  48. >
  49. >Is my data being mangled some how in the data entry? I've tried just
  50. >printing out 1 array element or not using the loop and naming each
  51. >element but nothing seems to work.
  52. >
  53. >If you can explain why this is happening and how to fix it my computer
  54. >would be greatful. I've been making some awful threats at it today. It
  55. >must be something simple I'm overlooking.
  56. >
  57. >Thanks again if you have helped me in the past and with this question.
  58. >
  59. >Please post or e-mail your response.
  60. >
  61. >Happy coding,
  62. >Andy
  63. >e-mail ishky@ix.netcom.com
  64.  
  65. Is there a particular reason you have declared scores as char?  Perhaps changing the declaration
  66. to a numeric type would help. :-)
  67.  
  68.